#include <header.h>

int main(){

    DIR *pdir = opendir("a");
    ERROR_CHECK(pdir,NULL,"opendir");

    int ret = chdir("a/b");
    ERROR_CHECK(ret,-1,"chdir");

    struct dirent *pdirent;

    struct stat st;
    while(1){
        pdirent = readdir(pdir);

        if(pdirent == NULL){
            break;
        }


        char *newname = pdirent->d_name;
        //char buf[1024] = {0};
        //sprintf(buf,"%s/%s", "a", newname);
        //int ret = stat(buf,&st);

        
        int ret = stat(pdirent->d_name, &st);
        ERROR_CHECK(ret,-1,"stat");

        printf("%o %lu %u %u %lu %ld %s\n",  
            st.st_mode & 0777,        // 权限（八进制）
            st.st_nlink,              // 硬链接数
            st.st_uid,                // 用户ID
            st.st_gid,                // 组ID
            st.st_size,               // 文件大小
            st.st_mtim.tv_sec,        // 修改时间戳
            pdirent->d_name           //文件名
            );

    }

    closedir(pdir);
    return 0;
}

